package com.huw.debuger;

import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;

import android.graphics.Color;
import android.graphics.Typeface;

import com.light.gamecomponents.physics.RollerPhysicsWorld;
import com.light.roller.Player;
import com.light.roller.Roller;

public class Debugger implements IUpdateHandler {
	
	public final static boolean DEBUG_MOD = false;
	public final static boolean JUMP_STAGE = false;
	public final static boolean UNLOCK_ALL_STAGE = false;
	public final static boolean ALWAYS_ALIVE = false;
	public static boolean HIDE_STATIC_WALL = false;
	public final static boolean AlPHA_STATIC_WALL = true;
	
	public Texture mFontTexture;
	public Font mFont;	
	public ChangeableText printText;
	public ChangeableText printText2;
	private Roller m_roller;
	private Camera m_camera;
	private Player m_player = null;	      


	public Debugger(Roller roller,Camera camera,Player player)
	{
		m_roller = roller;
		m_camera = camera;
		m_player = player;
	}
	
	public void onLoadResources()
	{
		this.mFontTexture = new Texture(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mFont = new Font(this.mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 10, true, Color.WHITE);
		m_roller.getEngine().getTextureManager().loadTexture(this.mFontTexture);
		m_roller.getEngine().getFontManager().loadFont(this.mFont);
	}
	
	public void onLoadScene(Scene scene,PhysicsWorld physicsworld) 
	{
		printText=new ChangeableText(0, 100, this.mFont, "Touch\n Point:", "Touch Point: XXXXXXXXXXXXXXXXXXXX".length());
		if(DEBUG_MOD)scene.attachChild(printText);
		printText2=new ChangeableText(0, 100, this.mFont, "debug", "                                                                 ".length());
		if(DEBUG_MOD)scene.attachChild(printText2);
		if(DEBUG_MOD)((RollerPhysicsWorld)physicsworld).registerUpdateHandler(this);

	}
	
	public void onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent)
	{
		if(DEBUG_MOD)printText.setText("("+pSceneTouchEvent.getX()+","+pSceneTouchEvent.getY()+")");			
	}
	
	
	@Override
	public void onUpdate(float pSecondsElapsed) {
		if(DEBUG_MOD)printText.setPosition(m_camera.getMinX(), m_camera.getMinY()+10);
		if(DEBUG_MOD)printText2.setPosition(m_camera.getMinX(), m_camera.getMinY()+10+50);
	}
	@Override
	public void reset() {
		// TODO Auto-generated method stub
		
	}
	
	public void showText(String str)
	{
		if(DEBUG_MOD)printText2.setText(str);
	}

}
